package com.theo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.theo.entity.CommentInfo;
import com.theo.mapper.CommentInfoMapper;
import com.theo.service.CommentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Service
public class CommentInfoServiceImpl extends ServiceImpl<CommentInfoMapper, CommentInfo> implements CommentInfoService {
    @Autowired
    private CommentInfoMapper commentInfoMapper;

    @Override
    public int saveCommentInfo(CommentInfo commentInfo) {
        return commentInfoMapper.insert(commentInfo);
    }

    @Override
    public int deleteCommentInfo(Integer id) {
        return commentInfoMapper.deleteById(id);
    }

    @Override
    public int updateCommentInfo(CommentInfo commentInfo) {
        return commentInfoMapper.updateById(commentInfo);
    }

    @Override
    public List<CommentInfo> queryAllCommentInfo() {
        return commentInfoMapper.selectList(null);
    }

    @Override
    public List<CommentInfo> queryCommentInfo(Integer id) {
        QueryWrapper<CommentInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("topic_id", id)
               .orderByDesc("create_time");
        return commentInfoMapper.selectList(wrapper);
    }

    @Override
    public CommentInfo queryCommentInfoById(Integer id) {
        return commentInfoMapper.selectById(id);
    }
}
